<?php

namespace App\Http\Controllers\Api\O1\UserCenter\Paper;

use Illuminate\Http\Request;
use Biz\Jobs\SiteEmailSendJob;
use Biz\Services\Site\SitePaperService;
use Biz\Requests\Site\SitePaperRequest;
use Biz\Resources\Site\SitePaperResource;
use Biz\Transformers\Site\PaperTransformer;
use Biz\Resources\Site\SitePaperResourceCollection;
use Lumen\Http\Resources\Json\DataResourceResponse;
use Biz\Mailers\Site\SitePaperAbstractSubmissionMail;
use Laravel\Lumen\Routing\Controller as BaseController;

/**
 * PaperController.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class PaperController extends BaseController
{
    /**
     * @var mixed
     */
    protected $service;

    /**
     * PaperController constructor.
     *
     * @param SitePaperService $service
     */
    public function __construct(SitePaperService $service)
    {
        $this->service = $service;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $results = $this->service->getUserPaperAbstractList($request);

        return new SitePaperResourceCollection($results);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param SitePaperRequest $request
     *
     * @return \Illuminate\Http\Response
     */
    public function store(SitePaperRequest $request)
    {
        $paper = $this->service->store($request);

        // Send email
        $mail = new SitePaperAbstractSubmissionMail($paper->abstract);
        dispatch(new SiteEmailSendJob($mail));

        return new SitePaperResource($paper);
    }

    /**
     * Display the specified resource.
     *
     * @param string $id
     *
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $paper = $this->service->show($id);

        return new PaperTransformer($paper);
    }
//
//    /**
//     * Update the specified resource in storage.
//     *
//     * @param SitePaperRequest $request
//     * @param string             $id
//     *
//     * @return \Illuminate\Http\Response
//     */
//    public function update(SitePaperRequest $request, $id)
//    {
//        $paper = $this->service->edit($id, $request->all());
//
//        return new SitePaperResource($paper);
//    }
//
//    /**
//     * Remove the specified resource from storage.
//     *
//     * @param string $id
//     *
//     * @return \Illuminate\Http\Response
//     */
//    public function destroy($id)
//    {
//        $result = $this->service->remove($id);
//
//        return new DataResourceResponse($result);
//    }
//
//    /**
//     * Remove the specified resource from storage.
//     *
//     * @param string $id
//     * @param string $locale
//     *
//     * @return \Illuminate\Http\Response
//     */
//    public function deleteTranslations($id, $locale)
//    {
//        $result =  $this->service->deleteTranslations($id, $locale);
//
//        return new DataResourceResponse($result);
//    }
}
